
import java.io.*;
import java.net.*;

//http://www3.ntu.edu.sg/home/ehchua/programming/java/J6a_Networking.html

//http://www.lauridmeyer.com/2012/04/simple-arduino-tcp-server-using-the-ethernetshield-and-a-java-client/
//http://www.lauridmeyer.com/2012/04/simple-arduino-tcp-client-using-the-ethernetshield-dhcp-and-a-java-server/


public class BatMonListener {
	
	ServerSocket server;
	int serverPort = 8888;
	
	public static void main(String[] args) {
		new BatMonListener().listen();
	}
	

   public BatMonListener() {
      try {
         server = new ServerSocket(serverPort);
         System.out.println("ServerSocket: " + server);
      } catch (IOException e) {
         e.printStackTrace();
      }
   }
   

   private void listen() {
      while (true) { 
         try {
            // Wait for connection. Block until a connection is made.
            Socket socket = server.accept();
            System.out.println("Socket: " + socket);
            // Start a new thread for each client to perform block-IO operations.
            new ClientThread(socket).start();
         } catch (IOException e) {
            e.printStackTrace();
         }
      }
   }

}
